<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div></div>
    <script>
        var div = document.querySelector('div');
        timer();

        function timer() {
            var time = new Date();
            var year = time.getFullYear();
            var month = time.getMonth() + 1;
            var date = time.getDate();
            var day = time.getDay();
            var hour = time.getHours();
            hour = hour < 10 ? '0' + hour : hour;
            var minute = time.getMinutes();
            minute = minute < 10 ? '0' + minute : minute;
            var second = time.getSeconds();
            second = second < 10 ? '0' + second : second;
            var arr = [
                '星期日',
                '星期一',
                '星期二',
                '星期三',
                '星期四',
                '星期五',
                '星期六',

            ]
            div.innerHTML = year + '年' + month + '月' + date + '日' + arr[day] + hour + ':' + minute + ':' + second;
        }
        setInterval(timer, 1000);
    </script>
</body>

</html>